package api_day13;

public class Consumer extends Thread{
    public Product product;

    public Consumer(Product product) {
        this.product = product;
    }
    @Override
    public void run() {
        while (true){
            product.lock.lock();
            while (!product.flag){
                try {
                    product.con.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            while (product.product > 0){
                product.product -= 1;
                System.out.println("消费了一个");
                if (product.product == 0) {
                    product.flag = false;
                }
                product.pro.signal();
            }
            product.lock.unlock();
        }
    }
}